#ifndef _TIMER_H_
#define _TIMER_H_

#include "mcu_base_def.h"

typedef union{
    volatile struct{
        u32 oneShot:1;
        u32 timerSize:1;    //0:16bit,1:32bit
        u32 timerPre:2;     //分频
        u32 reserve:1;
        u32 intEnable:1;    //中断开启,默认为1
        u32 timerMode:1;    //0:自由运行, 1:外设模式
        u32 timerEn:1;      //是否开启
    };
    volatile u32 val;
}timer_control_t;

enum{
    timerPre_div1 = 0b00,
    timerPre_div16 = 0b01,
    timerPre_div256 = 0b10,

    timerSize_16bit_counter = 0b0,
    timerSize_32bit_counter = 0b0,
};

typedef struct{
    volatile u32
    timer1Load,
    timer1Value,
    timer1Control,
    timer1IntClr,
    timer1RIS,
    timer1MIS,
    timer1BGLoad,
    reserve1;

    volatile u32
    timer2Load,
    timer2Value,
    timer2Control,
    timer2IntClr,
    timer2RIS,
    timer2MIS,
    timer2BGLoad,
    reserve2;
}timer_type_t;

enum{
    timer_type_t_sizeof = sizeof(timer_type_t),
};

#define TIMER1_BASE 0x40010000
#define TIMER2_BASE 0x40011000

static volatile timer_type_t* TIMER1 = (timer_type_t*)TIMER1_BASE;
static volatile timer_type_t* TIMER2 = (timer_type_t*)TIMER2_BASE;
INLINE void timer_start1(timer_type_t*t){
    volatile timer_control_t *c = (timer_control_t *)&t->timer1Control;
    c->timerEn = 1;
}

#endif
